<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%user_operate_log}}".
 *
 * @property string $id
 * @property int $created_at
 * @property string $created_by
 * @property string $yii_app_id
 * @property string $uri 路由
 * @property string $ip
 * @property string $json_data 记录数据
 *
 * @property User $createdBy
 * @property Yii2App $yiiApp
 */
class UserOperateLog extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%user_operate_log}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['created_at', 'created_by', 'yii_app_id', 'uri', 'ip'], 'required'],
            [['created_at', 'created_by', 'yii_app_id'], 'integer'],
            [['json_data'], 'string'],
            [['uri'], 'string', 'max' => 50],
            [['ip'], 'string', 'max' => 32],
            [['created_by'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['created_by' => 'id']],
            [['yii_app_id'], 'exist', 'skipOnError' => true, 'targetClass' => Yii2App::className(), 'targetAttribute' => ['yii_app_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'created_by' => Yii::t('app', 'Created By'),
            'yii_app_id' => Yii::t('app', 'Yii App ID'),
            'uri' => Yii::t('app', '路由'),
            'ip' => Yii::t('app', 'Ip'),
            'json_data' => Yii::t('app', '记录数据'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getYiiApp()
    {
        return $this->hasOne(Yii2App::className(), ['id' => 'yii_app_id']);
    }
}
